
use "$dhs2013\phkr61dt\PHKR61FL", clear

	do "edit_dhsvars.do"
	
	rename b1 birthmonth
	rename b2 birthyear
	rename v006 month
	rename v007 year 
	rename v016 day	
	
	g haddiarr=1 if h11==2
		replace haddiarr=0 if h11==0
		
	g hadfever=1 if h22==1
		replace hadfever=0 if h22==0
	
	g hadcough=1 if h31==2
		replace hadcough=0 if h31==0	
	g hadfevercough=max(hadfever,hadcough)
	g hadany=max(haddiarr, hadfever, hadcough)
	
	g pubsect_diarr=.
	foreach letter in a b  e {
		replace pubsect_diarr=1 if h12`letter' ==1
	}
	replace pubsect_diarr=0 if pubsect_diarr==. & haddiarr==1
	
	g brgsect_diarr=.
	foreach letter in  c d  {
		replace brgsect_diarr=1 if h12`letter' ==1
	}
	replace brgsect_diarr=0 if brgsect_diarr==. & haddiarr==1
	
	g pvtsect_diarr=.
	foreach letter in j k l m n o p  {
		replace pvtsect_diarr=1 if h12`letter'==1		
	}
	replace pvtsect_diarr=0 if pvtsect_diarr==. & haddiarr==1

	foreach type in fever cough fevercough {
		g pubsect_`type'=.
		foreach letter in a b e {
			replace pubsect_`type'=1 if h32`letter' ==1
		}
		replace pubsect_`type'=0 if pubsect_`type'==. & had`type'==1
			
		g brgsect_`type'=.
		foreach letter in c d {
			replace brgsect_`type'=1 if h32`letter' ==1
		}
		replace brgsect_`type'=0 if brgsect_`type'==. & had`type'==1

		g pvtsect_`type'=.
		foreach letter in j k l m n o p  {
			replace pvtsect_`type'=1 if h32`letter'==1		
		}
		replace pvtsect_`type'=0 if pvtsect_`type'==. & had`type'==1
	}
	
	g pubsect=pubsect_diarr==1|pubsect_fevercough==1
	g pvtsect=pvtsect_diarr==1|pvtsect_fevercough==1
	g brgsect=brgsect_diarr==1|brgsect_fevercough==1
		

	g pubsect_cond=pubsect
		replace pubsect_cond=. if haddiarr!=1 & hadfevercough!=1
	g pvtsect_cond=pvtsect
		replace pvtsect_cond=. if haddiarr!=1 & hadfevercough!=1
	g brgsect_cond=brgsect
		replace brgsect_cond=. if haddiarr!=1 & hadfevercough!=1
	
	g anysect_cond=max(pubsect_cond, pvtsect_cond, brgsect_cond)
	g anysect_fevercough=max(pubsect_fevercough, pvtsect_fevercough, brgsect_fevercough)
	g anysect_fever=max(pubsect_fever, pvtsect_fever, brgsect_fever) 
	g anysect_cough=max(pubsect_cough, pvtsect_cough, brgsect_cough) 
	
	g anysect=anysect_cond
	replace anysect=0 if hadany==0			

	keep  $keyvars month year day had* pub* pvt* any*  birthyear birthmonth 
		
	g provid=string(provcode,"%02.0f")
	g munid=string(provcode,"%02.0f") +string(municode, "%02.0f")
	g baranid=string(provcode,"%02.0f") +string(municode, "%02.0f") +string(barancode, "%03.0f")

	merge m:1 year month munid using "merged_ph_ncdc_dhs_raintemp", gen(_rain) keepusing(*temp *prec)
		drop if _rain==2
		drop _rain
		/*only armm provinces match up*/
		
	merge m:1 provid year month using "bcms_byprov_allph", gen(_prov)
		drop if _prov==2
		

	merge m:1 munid year month using "bcms_bymun_allph", gen(_mun)

	drop if _mun==2
	
		
	destring provid munid baranid, replace
	g a=1
	recode sex (2=0), gen(male)
	save "curative", replace	


	
